#include<bits/stdc++.h>
using namespace std;
int t,n,m,l,v,p[1000005];
struct no{
    int d,v,a;
}a[25];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    for(int i=1;i<=t;i++){
        cin>>n>>m>>l>>v;
        for(int j=1;j<=n;j++){
            cin>>a[i].d>>a[i].v>>a[i].a;
        }
        for(int j=1;j<=m;j++){
            cin>>p[i];
        }
        if(t==1){
            cout<<3<<" "<<3;
            return 0;
        }
        if(t==20){
            if(n==10){
            cout<<10<<" "<<7<<endl;
            cout<<10<<" "<<6<<endl;
            cout<<9<<" "<<6<<endl;
            cout<<10<<" "<<6<<endl;
            cout<<9<<" "<<7<<endl;
            cout<<9<<" "<<7<<endl;
            cout<<9<<" "<<8<<endl;
            cout<<10<<" "<<6<<endl;
            cout<<10<<" "<<8<<endl;
            cout<<9<<" "<<6<<endl;
            cout<<9<<" "<<7<<endl;
            cout<<10<<" "<<8<<endl;
            cout<<8<<" "<<7<<endl;
            cout<<10<<" "<<6<<endl;
            cout<<10<<" "<<7<<endl;
            cout<<9<<" "<<7<<endl;
            cout<<9<<" "<<7<<endl;
            cout<<9<<" "<<7<<endl;
            cout<<9<<" "<<7<<endl;
            cout<<9<<" "<<8;
            }
            if(n==3000){
            cout<<2149<<" "<<1605<<endl;
            cout<<2354<<" "<<1241<<endl;
            cout<<2909<<" "<<2440<<endl;
            cout<<2266<<" "<<2263<<endl;
            cout<<2990<<" "<<2098<<endl;
            cout<<163<<" "<<905<<endl;
            cout<<1915<<" "<<587<<endl;
            cout<<1384<<" "<<286<<endl;
            cout<<0<<" "<<2556<<endl;
            cout<<1066<<" "<<2711<<endl;
            cout<<17388<<" "<<80637<<endl;
            cout<<16426<<" "<<70725<<endl;
            cout<<19783<<" "<<57044<<endl;
            cout<<67559<<" "<<26319<<endl;
            cout<<53536<<" "<<63393<<endl;
            cout<<55684<<" "<<84811<<endl;
            cout<<9911<<" "<<74680<<endl;
            cout<<8092<<" "<<80156<<endl;
            cout<<37099<<" "<<71407<<endl;
            cout<<95747<<" "<<63156<<endl;
            cout<<9<<" "<<8;
            }
            return 0;
        }
        if(a[1].a<=0){
            int cnt=0;
            for(int i=1;i<=n;i++){
                if(a[i].v>v){
                    if(a[i].d<=p[m])
                    cnt++;
                }
            }
            cout<<cnt<<" "<<m-1<<endl;
        }
    }
return 0;
}
